package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.DynamicExposureRecordRequest;
import com.ytjj.qmyx.admin.model.request.PlatformStrictProfitRequest;
import com.ytjj.qmyx.admin.service.PlatformStrictProfitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 达人收益类-我的收益
 */
@RestController
@RequestMapping("/strictProfit")
@Slf4j
public class PlatformStrictProfitController {
    @Autowired
    private PlatformStrictProfitService platformStrictProfitService;

    @GetMapping("/list")
    public CommonResult list(@RequestParam(required = false)String userName,
                             @RequestParam(required = false) Integer userId,
                             @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return CommonResult.success(platformStrictProfitService.list(userName, userId, pageNum, pageSize));
    }

    @GetMapping("/detail")
    public CommonResult detail(@RequestParam Integer userId) {
        return CommonResult.success(platformStrictProfitService.detail(userId));
    }

    @PostMapping("/save")
    public CommonResult save(@RequestBody PlatformStrictProfitRequest request) {
        Integer result = platformStrictProfitService.save(request);
        if (null == result || result <= 0) {
            return CommonResult.failed("保存失败");
        }
        return CommonResult.success(result);
    }
    //todo 需要定时任务跑昨天的数据

    //yx_dynamic_exposure_record-------------------------------------------达人动态曝光+浏览量日记录表

    @GetMapping("/select")
    public CommonResult select(@RequestParam(required = false)String userName,
                               @RequestParam(required = false) Integer userId,
                               @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return CommonResult.success(platformStrictProfitService.select(userName, userId, pageNum, pageSize));
    }

    @PostMapping("/update")
    public CommonResult update(@RequestBody DynamicExposureRecordRequest request) {
        platformStrictProfitService.update(request);
        return CommonResult.success();
    }
}
